package com.pt.pok.protobuf;

import com.pt.pok.CommandListener;
import com.pt.pok.Dispatcher;
import com.pt.pok.GeneralProxyException;
import com.pt.pok.ProtocolConverter;
import com.pt.pok.model.PokerCommand;

/**
 * @author Roman.Ivanov@playtech.com, Andrey.Panfilov@playtech.com
 * @date 1/23/12 TODO: comment please
 */
public class ProtobufProtocolConverter
    implements ProtocolConverter<byte[]> {

    final Dispatcher<byte[]> dispatcher;

    ProtobufProtocolConverter(final Dispatcher<byte[]> dispatcher) {
        this.dispatcher = dispatcher;
    }

    public byte[] convertToProtocolCommand(PokerCommand command) {
        return dispatcher.convert(command);
    }

    public PokerCommand convertFromProtocolCommand(int classId, byte[] protocolCommand)
        throws GeneralProxyException {
        return dispatcher.handleDirect(classId, protocolCommand);
    }

    public void handleCommand(int classId, byte[] protocolMessage)
        throws GeneralProxyException {
        dispatcher.handle(classId, protocolMessage);
    }

    public void addCommandListener(CommandListener commandListener) {
        dispatcher.addCommandListener(commandListener);
    }

    public void removeCommandListener(CommandListener commandListener) {
        dispatcher.removeCommandListener(commandListener);
    }

}
